package com.readboottest.controller;

import com.readboottest.entity.response.BaseResponse;
import com.readboottest.util.FileUtil;
import com.readboottest.util.StringUtil;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import static com.readboottest.constant.GlobalConstants.SUCCESS;

/**
 * @author zhanghuiyong
 * @创建时间 2019年07月30日
 * @描述: 音乐播放接口
 **/
@RequestMapping("/rfy/music")
@RestController
@CrossOrigin
public class MusicController {
    /**
     * 播放音乐
     *
     * @return
     */
    @GetMapping("/play")
    @ResponseBody
    public BaseResponse playMusic(String musicPath, HttpServletRequest request, HttpServletResponse response) {
        BaseResponse musicBaseResponse = new BaseResponse<>();
        System.out.println("开始播放音乐");
        try {
            if (StringUtil.isNotEmpty(musicPath)) {
                FileUtil.playMusic(request, response, musicPath);
                musicBaseResponse.setStatus(SUCCESS);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return musicBaseResponse;
    }

}
